package com.example.renyang.happysell.MyAdapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.renyang.happysell.R;

import java.util.List;

import infClass.Food;

/**
 * Created by john on 16/4/17.
 */
public class MyAdapter extends BaseAdapter {
    private List<Food> foods;
    private LayoutInflater inflater;
 private Context context;
    public MyAdapter(List<Food> foods, LayoutInflater inflater) {
        this.foods = foods;
        this.inflater = inflater;
     //   this.context=context;
        //this.context=(android.content.Context)fragment_menu.class;
    }
    public void setContext(Context context){
        this.context=context;
    }
    @Override
   public int getCount() {
        return foods.size();
    }

    @Override
    public Object getItem(int position) {
        return foods.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    //渲染
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        convertView=inflater.inflate(R.layout.pro,null);
        ImageView snap=(ImageView)convertView.findViewById(R.id.snap);
        TextView title=(TextView)convertView.findViewById(R.id.Tit);
        final TextView content=(TextView)convertView.findViewById(R.id.content);
        title.setText(foods.get(position).getStorename());
        content.setText(foods.get(position).getFname());


        snap.setImageResource(bytesToInt(foods.get(position).getFoodpic(),0));
        snap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            Log.i("zx", foods.get(position).getFname());
            //  Intent intent=new Intent(,fragment_retailer.class);
                //   context.startActivity(intent);
              //  Intent intent=new Intent(fragment_mall,fragment_retailer.class);
            //   context.startActivity(in);
      //      Intent intent=new Intent(this.getClass(),fragment_retailer.class);
            /*    Intent intent=new Intent();
                intent.setClass(context,fragment_retailer.class);
                context.startActivity(intent);*/
            }
        });

        return convertView;
    }
    public static int bytesToInt(byte[] ary, int offset) {
        int value;
         value = (int) ((ary[offset]&0xFF) | ((ary[offset+1]<<8) & 0xFF00) | ((ary[offset+2]<<16)& 0xFF0000) | ((ary[offset+3]<<24) & 0xFF000000));
         return value;
       }


}
